#!/bin/bash
usage() {
  echo "Usage: $0 hostname"
}

if [ $UID -ne 0 ]; then
    echo -e "Permission Denied"
    exit 1
fi

if [ ! -f /root/.ssh/id_rsa ];then
  ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -q
  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
fi

hostname=$1
if [[ $# -eq 1 ]] && [[ "$hostname" != "" ]];then
  ssh-copy-id -i ~/.ssh/id_rsa.pub $hostname
else
  echo "Error: Missing required arguments."
  usage
fi
